<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 15-5-16
 * Time: 下午2:55
 */

class record extends shopAdminBase{
    function __construct() {
        parent::__construct();
        $this->cms->setPageTitle("报备管理");
        $this->cms->setControlFile("shop/record/record_control.json");
    }

    function indexTask($page=1){
        $this->cms->setActionTitle("报备信息");
        $url=WebRouter::init()->getQuestion("page=");
        $page=$page>=1? $page: 1;
        $countOfPage=20;
        $offset=($page-1)*$countOfPage;
        $user_info=$this->user->getLoginInfo();
        $goods=GoodsMode::init();
        $shop=ShopMode::init();
        $shop_id=$shop->getShopId($user_info['id']);
        list($gopen_ids,$goods_total)=$goods->getList($shop_id,null,null,null,'time', true,$countOfPage, $offset);
        $record=CommodityMode::init();
        $i=0;
        $record_total=0;
        $r['record']=array();
        foreach($gopen_ids as $v){
            list($goods_record,$record_num)=$record->getListByGopenId($v,$countOfPage,$offset,null);
            if(!empty($goods_record)&&isset($record_num)){
                foreach($goods_record as $k){
                    $r['record'][$i++]=$k;
                    $record_total++;
                }
            }
        }
        $r['pages']=new Page($page,$record_total,$countOfPage);
        $r['pages']->setPageCallback(create_function('$page','return "'.$url.'".$page;'));
        foreach($r['record'] as &$v){
            $r['goods_info']=$goods->getSimpleInfo($v['gopen_id']);
            $r['shop_info']=$shop->getDetail($r['goods_info']['shop_id']);
            $v['gopen_id']=$r['goods_info']['name'];
        }
        $r['recordState']=array(
            'record'=>"报备",'group'=>"团购"
        );
        $r['buyState']=array(
            '1'=>"已购买",'0'=>"未购买"
        );
        $r['currentState']=array(
            'waiting'=>"等待客服确认",'saw'=>"已看房",'deposit'=>"已缴纳订金",'front'=>"已交首付",'all'=>"已交全款",'finish'=>"完成销售",'overtime'=>"报备超时",'fake'=>"虚假报备",'profit'=>"已收到分成"
        );
        $r['today_time'] = date('Y-m-d');
        $this->cms->tableScene($r,"shop/record/record.php");
    }

    function sawTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'saw');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function unsawTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'waiting');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function depositTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'deposit');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function undepositTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'saw');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function frontTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'front');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function unfrontTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'deposit');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function allTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'all');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function unallTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'front');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function finishTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'finish');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function unfinishTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'all');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function profitTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'profit');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function unprofitTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'finish');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }

    function undoTask($id){
        $record=CommodityMode::init();
        $s=$record->setState($id,'saw');
        if($s){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="操作成功";
        }else{
            $r['message']="操作失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }
} 